﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleData.ObjectModel
{
	/// <summary>
	/// 
	/// </summary>
	public class DataObjectNameBase : IDataObjectName
	{
		private string fullName;

		#region [ .ctor ]

		/// <summary>
		/// Utilizado pelo EF
		/// </summary>
		protected DataObjectNameBase()
		{ }

		protected DataObjectNameBase( string name, string ns )
		{
			name.Throws().IfNullOrEmpty();
			ns.Throws().IfNullOrEmpty();

			this.Name = name;
			this.Namespace = ns;
			//this.FullName = String.Concat( ns, "[", name, "]" );
		}

		#endregion

		/// <summary>
		/// Obtém o nome que identifica o objeto
		/// </summary>
		public virtual string Name
		{
			get;
			protected set;
		}

		/// <summary>
		/// Obtém o namespace do objeto
		/// </summary>
		public virtual string Namespace
		{
			get;
			protected set;
		}

		#region IDataObjectName Members

		/// <summary>
		/// Obtém o nome completo que identifica únicamente o objeto
		/// </summary>
		public string FullName
		{
			get
			{
				if(this.fullName == null)
					this.fullName = String.Concat( this.Namespace, "[", this.Name, "]" );
				return this.fullName;
			}
		}

		#endregion

		public override string ToString()
		{
			return this.FullName;
		}

		public override bool Equals( object obj )
		{
			DataObjectNameBase dataName = obj as DataObjectNameBase;

			if ( dataName == null )
				return false;
			else
				return this.FullName.Equals( dataName.FullName, StringComparison.InvariantCultureIgnoreCase );
		}

		public override int GetHashCode()
		{
			return this.FullName.GetHashCode();
		}
	}
}
